package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIAthletics implements IUIWindows {

	DWFrame m_fail_frame = null;
	DWFrame m_win_frame = null;
	DWTitle m_win_tit;
	DWTitle m_fail_tit;
	DWBackground m_win_xbj_up_bg;
	DWBackground m_fail_xbj_up_bg;
	DWBackground m_win_xbj_down_bg;
	DWBackground m_fail_xbj_down_bg;

	DWImageBox m_win_ima;
	DWImageBox m_fail_ima;
	Bitmap m_cr_win = null;
	Bitmap m_cr_fail = null;
	Bitmap m_cr_but = null;
	Bitmap m_cr_but_1 = null;
	Bitmap m_cr_countdown = null;

	DWButton m_win_but;
	DWButton m_fail_but;
	Boolean m_flag_1;

	public void Athletics_Win() {
		if (DWControlsManager.getInstance().contains(m_win_frame)) {
			if (m_win_frame != null) {
				DWControlsManager.getInstance().removeControl(m_win_frame);
			}
		}
		// //画布
		m_win_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_win_frame.setClickClose(false);

		// 标题
		m_win_tit = new DWTitle("", m_win_frame);
		m_win_frame.addControl(m_win_tit);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit_win);
		m_tit_ima.setNearAnchor(m_win_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_win_frame.addControl(m_tit_ima);

		// 上面的小背景
		m_win_xbj_up_bg = new DWBackground(m_win_frame.getShowWidth() - 20, (m_win_frame.getShowHeight() - (m_win_tit.getShowHeight() - 20) - 35) / 2);
		m_win_xbj_up_bg.setNearAnchor(m_win_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 15 + (m_win_tit.getShowHeight() - 20));
		m_win_frame.addControl(m_win_xbj_up_bg);

		// 下面的小背景
		m_win_xbj_down_bg = new DWBackground(m_win_xbj_up_bg.getShowWidth(), (m_win_frame.getShowHeight() - (m_win_tit.getShowHeight() - 20) - 40) / 2);
		m_win_xbj_down_bg.setNearAnchor(m_win_xbj_up_bg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		m_win_frame.addControl(m_win_xbj_down_bg);

		// 上面的textbox
		DWTextbox m_win_name = new DWTextbox("", m_win_xbj_up_bg.getShowWidth() - 35, m_win_xbj_up_bg.getShowHeight() - 20);
		if (state == 1) {
			m_win_name.setText("<mark c=00BBFF>" + name2 + "</mark>" + "被" + "<mark c=FFBB11>" + name1 + "</mark>" + "击败" + DWControlTools.CHANGE_ROW + "竞技前分数：" + "<mark c=00BBFF>" + haveScore
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW + "竞技后得分：" + "<mark c=FF3300>" + addScore + "</mark>" + "分");
		} else if (state == 2) {
			m_win_name.setText("<mark c=00BBFF>" + name2 + "</mark>" + "被" + "<mark c=FFBB11>" + name1 + "</mark>" + "击败" + DWControlTools.CHANGE_ROW + "<mark c=FFBB11>" + f1name + "</mark>" + "："
					+ "剩余" + "<mark c=FF3300>" + f1amount + "</mark>" + "人" + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + f2name + "</mark>" + "：" + "剩余" + "<mark c=FF3300>" + f2amount
					+ "</mark>" + "人" + DWControlTools.CHANGE_ROW + "竞技前分数：" + "<mark c=00BBFF>" + haveScore + "</mark>" + "分" + DWControlTools.CHANGE_ROW + "竞技后得分：" + "<mark c=FF3300>" + addScore
					+ "</mark>" + "分");
		}

		m_win_name.setNearAnchor(m_win_xbj_up_bg, Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 15, 0);
		m_win_frame.addControl(m_win_name);

		// 胜利的图片
		m_win_ima = new DWImageBox(m_cr_win);
		m_win_ima.setNearAnchor(m_win_xbj_up_bg, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, -15, 0);
		m_win_frame.addControl(m_win_ima);

		// ///下面布局
		m_win_but = new DWButton("", m_cr_countdown);
		m_win_but.setNearAnchor(m_win_xbj_down_bg, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 5);
		m_win_frame.addControl(m_win_but);

		DWTextbox m_win_text = new DWTextbox("奖励如下：" + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "战功点数：" + "</mark>" + zhangong + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "经验值："
				+ "</mark>" + exp + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "金币：" + "</mark>" + money + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + "今日您还可再参加次数：" + "</mark>" + haveNext,
				m_win_xbj_down_bg.getShowWidth() - 20, m_win_xbj_down_bg.getShowHeight() - m_cr_countdown.getHeight() - 10);
		m_win_text.setNearAnchor(m_win_xbj_down_bg, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, m_cr_countdown.getHeight() + 5);
		m_win_frame.addControl(m_win_text);
		DWControlsManager.getInstance().addControl(m_win_frame);
	}

	public void Athletics_Fail() {
		if (DWControlsManager.getInstance().contains(m_fail_frame)) {
			if (m_fail_frame != null) {
				DWControlsManager.getInstance().removeControl(m_fail_frame);
			}
		}
		// //画布
		m_fail_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_fail_frame.setClickClose(false);
		// 标题
		m_fail_tit = new DWTitle("", m_fail_frame);
		m_fail_frame.addControl(m_fail_tit);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit_fail);
		m_tit_ima.setNearAnchor(m_fail_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_fail_frame.addControl(m_tit_ima);

		// 上面的小背景
		m_fail_xbj_up_bg = new DWBackground(m_fail_frame.getShowWidth() - 20, (m_fail_frame.getShowHeight() - (m_fail_tit.getShowHeight() - 20) - 40) / 2);
		m_fail_xbj_up_bg.setNearAnchor(m_fail_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 15 + (m_fail_tit.getShowHeight() - 20));
		m_fail_frame.addControl(m_fail_xbj_up_bg);

		// 下面的小背景
		m_fail_xbj_down_bg = new DWBackground(m_fail_xbj_up_bg.getShowWidth(), (m_fail_frame.getShowHeight() - (m_fail_tit.getShowHeight() - 20) - 35) / 2);
		m_fail_xbj_down_bg.setNearAnchor(m_fail_xbj_up_bg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		m_fail_frame.addControl(m_fail_xbj_down_bg);

		// 上面的textbox
		DWTextbox m_fail_name = new DWTextbox("", m_fail_xbj_up_bg.getShowWidth() - 35, m_fail_xbj_up_bg.getShowHeight() - 20);
		if (state == 1) {
			m_fail_name.setText("<mark c=00BBFF>" + name1 + "</mark>" + "被" + "<mark c=FFBB11>" + name2 + "</mark>" + "击败" + DWControlTools.CHANGE_ROW + "竞技前分数：" + "<mark c=00BBFF>" + haveScore
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW + "竞技后得分：" + "<mark c=FF3300>" + addScore + "</mark>" + "分");
		} else if (state == 2) {
			m_fail_name.setText("<mark c=00BBFF>" + name1 + "</mark>" + "被" + "<mark c=FFBB11>" + name2 + "</mark>" + "击败" + DWControlTools.CHANGE_ROW + "<mark c=FFBB11>" + f1name + "</mark>" + "："
					+ "剩余" + "<mark c=FF3300>" + f1amount + "</mark>" + "人" + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + f2name + "</mark>" + "：" + "剩余" + "<mark c=FF3300>" + f2amount
					+ "</mark>" + "人" + DWControlTools.CHANGE_ROW + "竞技前分数：" + "<mark c=FFBB11>" + haveScore + "</mark>" + "分" + DWControlTools.CHANGE_ROW + "竞技后得分：" + "<mark c=55FF00>" + addScore
					+ "</mark>" + "分");
		}
		m_fail_name.setNearAnchor(m_fail_xbj_up_bg, Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 15, 0);
		m_fail_frame.addControl(m_fail_name);

		// 胜利的图片
		m_fail_ima = new DWImageBox(m_cr_fail);
		m_fail_ima.setNearAnchor(m_fail_xbj_up_bg, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, -15, 0);
		m_fail_frame.addControl(m_fail_ima);

		// ///下面布局
		m_fail_but = new DWButton("", m_cr_countdown);
		m_fail_but.setNearAnchor(m_fail_xbj_down_bg, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 5);
		m_fail_frame.addControl(m_fail_but);

		DWTextbox m_fail_text = new DWTextbox("奖励如下：" + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "战功点数：" + "</mark>" + zhangong + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "经验值："
				+ "</mark>" + exp + DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "金币：" + "</mark>" + money + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + "今日您还可再参加次数：" + "</mark>" + haveNext,
				m_fail_xbj_down_bg.getShowWidth() - 20, m_fail_xbj_down_bg.getShowHeight() - m_cr_countdown.getHeight() - 10);
		m_fail_text.setNearAnchor(m_fail_xbj_down_bg, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, m_cr_countdown.getHeight() + 5);
		m_fail_frame.addControl(m_fail_text);
		DWControlsManager.getInstance().addControl(m_fail_frame);
	}

	public void init() {
		// 加载图片
		m_cr_tit = UIWindows.createImage("/img/newui/tishi_1.gnp");
		m_cr_tit_win = UIWindows.createImage("/img/newui/jingjishenglibt.gnp");
		m_cr_tit_fail = UIWindows.createImage("/img/newui/jingjishibaibt.gnp");
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp"); // //按钮的图片
		m_cr_but_1 = UIWindows.createImage("/img/newui/anniu_6ax.gnp"); // //按钮点击后变的图片
		m_cr_win = UIWindows.createImage("/img/newui/fubensl_1.gnp");
		m_cr_fail = UIWindows.createImage("/img/newui/fubensb_1.gnp");
		m_cr_countdown = UIWindows.createImage("/img/newui/fubenshenglidmk_1.gnp");
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 叉键退出
		m_cr_bj = UIWindows.createImage("/img/newui/daojishipai_1.gnp");
	}

	DWFrame m_count_frame = null;
	DWImageBox m_tuichu_ima;
	DWButton m_count_ima_but;
	DWTextbox m_count_text;
	DWTextbox m_text;
	Bitmap m_cr_tuichu = null;
	DWBackground m_count_xbj;
	DWButton m_submit_but;
	Bitmap m_cr_tit = null;
	Bitmap m_cr_tit_win = null;
	Bitmap m_cr_tit_fail = null;
	Bitmap m_cr_tit_shegnli = null;
	Bitmap m_cr_tit_shibai = null;

	public void Count_down() {
		if (DWControlsManager.getInstance().contains(m_count_frame)) {
			if (m_count_frame != null) {
				DWControlsManager.getInstance().removeControl(m_count_frame);
			}
		}
		m_flag_1 = true;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH)
		{
			m_count_frame = new DWFrame(500, 400);
		}
		else
		{
			m_count_frame = new DWFrame(400, 300);
		}
		m_count_frame.setClickClose(false);

		DWTitle m_tit = new DWTitle("", m_count_frame);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

		m_count_xbj = new DWBackground(m_count_frame.getShowWidth() - 30, m_count_frame.getShowHeight() - (m_tit.getShowHeight() - 20) - 25);
		m_count_xbj.setNearAnchor(m_count_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 15, 10 + (m_tit.getShowHeight() - 20));

		m_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima.setNearAnchorUn(m_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_tuichu_ima.addListener(m_tuichu_lis);
		m_tuichu_ima.setTouchZoomIn(40, 40);

		m_count_ima_but = new DWButton("", m_cr_countdown);
		m_count_ima_but.setNearAnchor(m_count_xbj, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 5);

		if (state == 1) {
			m_count_text = new DWTextbox("个人竞技场已经找到对手，是否进入竞技？", m_count_xbj.getShowWidth() - 80, m_count_xbj.getShowHeight() - m_cr_but.getHeight() - m_count_ima_but.getShowHeight() - 30);
		} else if (state == 2) {
			m_count_text = new DWTextbox("家族竞技场已经找到对手，是否进入竞技？", m_count_xbj.getShowWidth() - 80, m_count_xbj.getShowHeight() - m_cr_but.getHeight() - m_count_ima_but.getShowHeight() - 30);
		} else if (state == 5) {
			m_count_text = new DWTextbox("阵营战场人数已满足参与条件，是否进入战场？", m_count_xbj.getShowWidth() - 80, m_count_xbj.getShowHeight() - m_cr_but.getHeight() - m_count_ima_but.getShowHeight() - 30);
		}
		m_count_text.setNearAnchor(m_count_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 40, m_count_ima_but.getShowHeight() + 15);

		m_submit_but = new DWButton("确定", m_cr_but);
		m_submit_but.setDownImage(m_cr_but_1);
		m_submit_but.setNearAnchor(m_count_text, Tools.RIGHT_TOP, Tools.RIGHT_BOTTOM, 0, 15);
		m_submit_but.addListener(m_submit_lis);

		m_count_frame.addControl(m_tit);
		m_count_frame.addControl(m_tit_ima);
		m_count_frame.addControl(m_count_xbj);
		m_count_frame.addControl(m_tuichu_ima);
		m_count_frame.addControl(m_count_ima_but);
		m_count_frame.addControl(m_count_text);
		m_count_frame.addControl(m_submit_but);
		DWControlsManager.getInstance().addControl(m_count_frame);

	}

	private DWListener m_submit_lis = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			DWGameManager.getInstance().getSendMessage().sendARENREQUEST((byte) 1, state, id);
			DWControlsManager.getInstance().removeControl(m_count_frame);
			Tools.debugPrintln("发送进入竞技场的类型：" + state);
			m_flag_1 = false;
			if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_assistant.m_assistant_frame)) {
				DWControlsManager.getInstance().removeControl(UIWindows.getInstance().m_assistant.m_assistant_frame);
			}
		}
	};
	private DWListener m_tuichu_lis = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			if (state == 1) {
				final DWMessageBox mb = new DWMessageBox("温馨提示", "您确定退出个人竞技场？");
				mb.addListener(new DWListener() {

					public void OnDoubleClick() {

					}

					public void OnClick() {
						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
							m_flag_1 = false;
							DWGameManager.getInstance().getSendMessage().sendARENREQUEST((byte) 0, state, id);
							Tools.debugPrintln("发送进入竞技场的类型：" + state);
							DWControlsManager.getInstance().removeControl(mb);
							DWControlsManager.getInstance().removeControl(m_count_frame);

							if (UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index] != null) {
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_description);
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setTextColor(Tools.WHITE);
								UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index].setName("立即参加");
							}
						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
							DWControlsManager.getInstance().removeControl(mb);
						}
					}
				});
				DWControlsManager.getInstance().addControl(mb);
			} else if (state == 2) {
				final DWMessageBox mb = new DWMessageBox("温馨提示", "您确定退出家族竞技场？");
				mb.addListener(new DWListener() {

					public void OnDoubleClick() {

					}

					public void OnClick() {
						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
							m_flag_1 = false;
							DWGameManager.getInstance().getSendMessage().sendARENREQUEST((byte) 0, state, id);
							Tools.debugPrintln("发送进入竞技场的类型：" + state);
							DWControlsManager.getInstance().removeControl(mb);
							DWControlsManager.getInstance().removeControl(m_count_frame);

							if (UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index] != null) {
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_description);
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setTextColor(Tools.WHITE);
								UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index].setName("立即参加");
							}
						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
							DWControlsManager.getInstance().removeControl(mb);
						}
					}
				});
				DWControlsManager.getInstance().addControl(mb);
			} else if (state == 5) {
				final DWMessageBox mb = new DWMessageBox("温馨提示", "您确定退出阵营战场？");
				mb.addListener(new DWListener() {

					public void OnDoubleClick() {

					}

					public void OnClick() {
						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
							m_flag_1 = false;
							DWGameManager.getInstance().getSendMessage().sendARENREQUEST((byte) 0, state, id);
							Tools.debugPrintln("发送进入竞技场的类型：" + state);
							DWControlsManager.getInstance().removeControl(mb);
							DWControlsManager.getInstance().removeControl(m_count_frame);

							if (UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index] != null) {
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_description);
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setTextColor(Tools.WHITE);
								UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index].setName("立即参加");
							}
						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
							DWControlsManager.getInstance().removeControl(mb);
						}
					}
				});
				DWControlsManager.getInstance().addControl(mb);
			}
		}
	};

	public void open(byte index) {
		switch (index) {
			case 0:
				Count_down();
				break;
			case 1:
				Athletics_Win();
				break;
			case 2:
				Athletics_Fail();
				break;
		}
	}

	public void close(byte index) {
	}

	public void dispose() {
	}

	DWFrame m_line_frame = null;
	DWTitle m_line_tit;
	DWBackground m_line_xbj;
	DWTextbox m_line_text;
	DWButton m_line_but_count;
	DWButton m_line_but_submit;
	DWImageBox m_line_tc;
	/**
	 * 是否同意进入竞技场
	 * 
	 * @param dis
	 * @throws IOException
	 */
	long id;
	byte state;

	public void recvIsImmediatelyInto(DataInputStream dis) throws IOException {
		Tools.debugPrintln("是否进入竞技场？");
		state = dis.readByte(); // 1个人，２家族 ，5阵营战场
		Tools.debugPrintln("1个人，2家族,5阵营战场：" + state);
		id = dis.readLong(); // id
		timer = dis.readByte();// 倒计时秒数
		m_start_time = System.currentTimeMillis();// 读取时截取系统时间
		Tools.debugPrintln("id:" + id + "timer:" + timer);
		Count_down();
		m_count_ima_but.setName(Integer.toString(timer));
		if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_assistant.m_assistant_frame)) {
			UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index]
					.setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows.getInstance().m_assistant.m_index].m_description);
			UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setTextColor(Tools.WHITE);
			UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index].setName("立即参加");
			UIWindows.getInstance().m_assistant.m_activity_list[UIWindows.getInstance().m_assistant.m_index].m_count_donw = 0;
		}
	}

	/**
	 * \ 倒计时
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvDJS(DataInputStream dis) throws IOException {
		byte state = dis.readByte();// 1：进入竞技场，准备战斗前
		if (state == 1) {
			short time = dis.readShort(); //
		}
	}

	private byte timer;
	private long m_start_time = 0;

	public void Timer() {
		if (DWControlsManager.getInstance().contains(m_count_frame)) {
			if (timer > 0) {
				if (m_start_time == 0) {
					m_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (timer - (currentTime - m_start_time) / 1000);
				if (index < 0) {
					m_start_time = 0;
				} else {
					m_count_ima_but.setName(Integer.toString(index));
					if (m_flag_1 == true) {
						if (index == 0) {
							m_start_time = 0;
							timer = 0;
							DWControlsManager.getInstance().removeControl(m_count_frame);
							if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_assistant.m_assistant_frame)) {
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_description);
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows.getInstance().m_assistant.m_index].setTextColor(Tools.WHITE);
								UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index].setName("立即参加");
							}
							DWGameManager.getInstance().getSendMessage().sendARENREQUEST((byte) 0, state, id);
							Tools.debugPrintln("退出进入竞技场的类型：" + state);
						}
					}
				}
			}
		}
	}

	public void logic() {
		Timer();
		Over_win();
		Over_fail();
		ChangjingTime();

	}

	/**
	 * 竞技场结算界面
	 * 
	 * @param dis
	 * @throws IOException
	 */
	String name1;
	String name2;
	int haveScore;// 原有分数
	int addScore;// 新加分数
	int zhangong; // 奖励战功
	int exp;// 经验
	int money;
	byte haveNext; // 可再参加次数
	byte CountDown; // 秒数
	byte m_over_1;
	private long m_over_count_1 = 0;
	private long m_over_count_2 = 0;

	public void recvOVER(DataInputStream dis) throws IOException {
		byte state = dis.readByte();// 1胜利　，0　失败
		Tools.debugPrintln("state:" + state);
		name1 = dis.readUTF();
		name2 = dis.readUTF();
		haveScore = dis.readInt();// 原有分数
		addScore = dis.readInt();// 新加分数
		zhangong = dis.readInt(); // 奖励战功
		exp = dis.readInt();// 经验
		money = dis.readInt();// 金币
		haveNext = dis.readByte(); // 可再参加次数
		CountDown = dis.readByte(); // 秒数

		Tools.debugPrintln("CountDown:" + CountDown);
		Tools.debugPrintln("haveNext:" + haveNext);
		Tools.debugPrintln("name1:" + name1);
		Tools.debugPrintln("name2:" + name2);
		m_over_1 = CountDown;
		m_over_count_1 = System.currentTimeMillis();// 读取时截取系统时间
		m_over_count_2 = System.currentTimeMillis();// 读取时截取系统时间
		if (state == 1) {
			Athletics_Win();
			m_win_but.setName(CountDown + "");
		} else if (state == 0) {
			Athletics_Fail();
			m_fail_but.setName(m_over_1 + "");
		}
	}

	public void Over_win() {
		if (DWControlsManager.getInstance().contains(m_win_frame)) {
			if (CountDown > 0) {
				if (m_over_count_1 == 0) {
					m_over_count_1 = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (CountDown - (currentTime - m_over_count_1) / 1000);
				if (index < 0) {
					m_over_count_1 = 0;
				} else {
					m_win_but.setName(index + "");
					if (index == 0) {
						if (DWControlsManager.getInstance().contains(m_win_frame)) {
							DWControlsManager.getInstance().removeControl(m_win_frame);
						}
						CountDown = 0;
					}
				}
			}
		}
	}

	public void Over_fail() {
		if (DWControlsManager.getInstance().contains(m_fail_frame)) {
			if (m_over_1 > 0) {
				if (m_over_count_2 == 0) {
					m_over_count_2 = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (m_over_1 - (currentTime - m_over_count_2) / 1000);
				if (index < 0) {
					m_over_count_2 = 0;
				} else {
					m_fail_but.setName(index + "");
					// if (m_flag_3 == true) {
					if (index == 0) {
						if (DWControlsManager.getInstance().contains(m_fail_frame)) {
							DWControlsManager.getInstance().removeControl(m_fail_frame);
						}
						m_over_1 = 0;
					}
					// }
				}
			}
		}
	}

	/**
	 * 读取家族竞技场剩余人数
	 * 
	 * @param dis
	 * @throws IOException
	 */
	/**
	 * 家族竞技场
	 */
	String f1name;
	byte f1amount;
	String f2name;
	byte f2amount;

	@SuppressWarnings("static-access")
	public void recvFamilyArenaRoleAmount(DataInputStream dis) throws IOException {
		f1name = dis.readUTF();
		f1amount = dis.readByte();
		f2name = dis.readUTF();
		f2amount = dis.readByte();
		UIWindows.getInstance().m_main.closeTaskList();
		UIWindows.getInstance().m_main.m_jingji_bg.setShow(true);
		UIWindows.getInstance().m_main.m_jingji_tb.setShow(true);
		UIWindows.getInstance().m_main.m_jingji_tb.setText("<mark c=FFBB11>" + f1name + "</mark>" + "：" + "剩余" + "<mark c=FF3300>" + f1amount + "</mark>" + "人" + DWControlTools.CHANGE_ROW
				+ "<mark c=00BBFF>" + f2name + "</mark>" + "：" + "剩余" + "<mark c=FF3300>" + f2amount + "</mark>" + "人");
		Tools.debugPrintln("家族1：" + f1name);
		Tools.debugPrintln("1人数：" + f1amount);
		Tools.debugPrintln("家族2：" + f2name + "1人数：");
		Tools.debugPrintln("2人数：" + f2amount);
	}

	public void recvFamilyRemove(DataInputStream dis) throws IOException {
		UIWindows.getInstance().m_main.m_jingji_bg.setShow(false);
		UIWindows.getInstance().m_main.m_jingji_tb.setShow(false);
		UIWindows.getInstance().m_main.OpenTaskList();
	}

	byte m_type;
	int m_changjing_time;
	private long m_changjing_start_time = 0;

	public void recvChangjingTime(DataInputStream dis) throws IOException {
		m_type = dis.readByte();
		m_changjing_time = dis.readInt();
		Tools.debugPrintln("类型："+m_type);
		Tools.debugPrintln("倒计时时间："+m_changjing_time);
		m_changjing_start_time = System.currentTimeMillis();// 读取时截取系统时间
		Changjing_Time();
	}

	public void ChangjingTime() {
		if(DWControlsManager.getInstance().contains(m_changjing_frame))
		{
			if (m_changjing_time > 0) {
				if (m_changjing_start_time == 0) {
					m_changjing_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (m_changjing_time - (currentTime - m_changjing_start_time) / 1000);
				if (index < 0) {
					m_changjing_start_time = 0;
				} else {
					if (index == 0) {
						m_changjing_start_time = 0;
						m_changjing_time = 0;
						if(DWControlsManager.getInstance().contains(m_changjing_frame))
						{
							DWControlsManager.getInstance().removeControl(m_changjing_frame);
						}
					}
					else
					{
						m_changjing_time_tb.setName((index/60)+" : "+(index%60));
					}
				}
			}
		}
	}
	
	public DWFrame m_changjing_frame = null;
	public Bitmap m_cr_bj = null;
	public DWImageBox m_bj_ima = null;
	public DWLabel m_changjing_time_tb;
	
	public void Changjing_Time()
	{
		if(DWControlsManager.getInstance().contains(m_changjing_frame))
		{
			if(m_changjing_frame != null)
			{
				DWControlsManager.getInstance().removeControl(m_changjing_frame);
			}
		}
		m_changjing_frame = new DWFrame(m_cr_bj.getWidth(), m_cr_bj.getHeight());
		m_changjing_frame.m_null_frame =true;
		m_changjing_frame.setClickClose(false);
		m_changjing_frame.setTouchZoomIn(0, 0);
		m_changjing_frame.setShield(true);
		m_changjing_frame.setThrough(true);
		m_changjing_frame.setNearAnchor(UIWindows.getInstance().m_main.m_Uimain_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0,0);
		DWControlsManager.getInstance().addControl(m_changjing_frame);
		
		m_bj_ima = new DWImageBox(m_cr_bj);
		m_bj_ima.setNearAnchor(m_changjing_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_changjing_frame.addControl(m_bj_ima);
		
		m_changjing_time_tb = new DWLabel((m_changjing_time/60)+" : "+(m_changjing_time%60));
		m_changjing_time_tb.setShowWideHigh(m_bj_ima.getShowWidth(), m_bj_ima.getShowHeight());
		m_changjing_time_tb.setBackgroundColor(Tools.ALPHA);
		m_changjing_time_tb.setTextColor(Tools.RED);
		m_changjing_time_tb.setFont(DWFont.getFont((m_bj_ima.getShowHeight()-25)));
		m_changjing_time_tb.setNearAnchor(m_bj_ima, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_changjing_frame.addControl(m_changjing_time_tb);
	}
}
